using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Security.Cryptography;

namespace NET_Client
{
    public partial class Form1 : Form
    {
        NetClient nclient;
        public PictureBox[] pic = new PictureBox[12];
        SendData sd = new SendData();    // Packet for Send to Server
        ReciveData rd = new ReciveData(); // Recive packet with list players 

        tplayer[] players = new tplayer[12]; // local players array 
        tplayer player;

        public Form1()
        {
            InitializeComponent();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
        public int GetMD5()
        {
            MD5 md5 = System.Security.Cryptography.MD5.Create();
            string myIP = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList[0].ToString();
            return myIP.GetHashCode();
        }
        private void Form1_Load(object sender, EventArgs e)
        {



        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 12; i++)
            {
                pic[i] = new PictureBox();
                pic[i].Visible = false;
                pic[i].Image = pictureBox1.Image;
                pic[i].Height = pictureBox1.Height;
                pic[i].Width = pictureBox1.Width;
                pic[i].Top = 10;
                pic[i].Left = 10;
                pic[i].SizeMode = pictureBox1.SizeMode;
                this.Controls.Add(pic[i]);
            }
            pic[1].Visible = true;

            //nclient = new NetClient();
            //nclient.Start("192.168.1.77");
            //sd.player.ID_MD5 = GetMD5();
            //player.ID_MD5 = sd.player.ID_MD5;
            //nclient.Send(sd);
            //nclient.Receive(out rd);     
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (nclient != null)
                if(pic != null)
                if (nclient.Handle.Connected == true)
                {
                    sd.player.x = e.X;
                    sd.player.y = e.Y;
                    player.x = e.X;
                    player.y = e.Y;
                    pic[1].Left = sd.player.x;
                    pic[1].Top = sd.player.y;
                }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            int current_count_players = 1;
            nclient.Send(sd);
            nclient.Receive(out rd);
            if (rd.count_player > current_count_players)
            { 
               
            }
        }
    }
}